// 1 - START DROPDOWN SLIDER SCRIPTS ------------------------------------------------------------------------

$(document).ready(function () {
    $(".showhide-account").click(function () {
        $(".account-content").slideToggle("fast");
        $(this).toggleClass("active");
        return false;
    });
});

$(document).ready(function () {
    $(".action-slider").click(function () {
        $("#actions-box-slider").slideToggle("fast");
        $(this).toggleClass("activated");
        return false;
    });
});

//  END ----------------------------- 1

// 2 - START LOGIN PAGE SHOW HIDE BETWEEN LOGIN AND FORGOT PASSWORD BOXES--------------------------------------

$(document).ready(function () {
	$(".forgot-pwd").click(function () {
	$("#loginbox").hide();
	$("#forgotbox").show();
	return false;
	});

});

$(document).ready(function () {
	$(".back-login").click(function () {
	$("#loginbox").show();
	$("#forgotbox").hide();
	return false;
	});
});

// END ----------------------------- 2



// 3 - MESSAGE BOX FADING SCRIPTS ---------------------------------------------------------------------

$(document).ready(function() {
	$(".close-yellow").click(function () {
		$("#message-yellow").fadeOut("slow");
	});
/*	$(".close-red").click(function () {
		$("#message-red").fadeOut("slow");
	});
*/
	
	$(".close-blue").click(function () {
		$("#message-blue").fadeOut("slow");
	});
/*	
	$(".close-green").click(function () {
		$("#message-green").fadeOut("slow");
	});
/**/
	
	$(".close-red").click(function () {
		$(this).parent().fadeOut("slow");
	});
	
	$(".close-green").click(function () {
		$(this).parent().fadeOut("slow");
	});
});

// END ----------------------------- 3



// 4 - CLOSE OPEN SLIDERS BY CLICKING ELSEWHERE ON PAGE -------------------------------------------------------------------------

$(document).bind("click", function (e) {
    if (e.target.id != $(".showhide-account").attr("class")) $(".account-content").slideUp();
});

$(document).bind("click", function (e) {
    if (e.target.id != $(".action-slider").attr("class")) $("#actions-box-slider").slideUp();
});
// END ----------------------------- 4
 
 
 
// 5 - TABLE ROW BACKGROUND COLOR CHANGES ON ROLLOVER -----------------------------------------------------------------------
/*
$(document).ready(function () {
    $('#product-table	tr').hover(function () {
        $(this).addClass('activity-blue');
    },
    function () {
        $(this).removeClass('activity-blue');
    });
});
 */
// END -----------------------------  5
 
 
 
 // 6 - DYNAMIC YEAR STAMP FOR FOOTER -----------------------------------------------------------------------

 $('#spanYear').html(new Date().getFullYear()); 
 
// END -----------------------------  6 
  
/*=================================  Michael Custom ================================*/
//Hàm Lock Screen lại
	function lockScreen(){
		$.blockUI({
			message: '<img width="50px" heigth="50" src="'+loadingUrl+'" alt="" />',
			css: { border:'none'}
		});
	}

	//Giải phóng màn hình, không lock nữa
	function releaseScreen(){
		//$(document).ajaxStop($.unblockUI);
		$.unblockUI();
	}
	
$(document).ready(function(){
	
	if(typeof defaultLanguage === 'undefined'){
		
	}else{
		//console.log(defaultLanguage);
		$('img[name='+defaultLanguage+']').attr("style","border:1px solid red;");
		
		//image at the top right corner header. Use to change default Language
		$('img[id='+defaultLanguage+']').attr("style","border:1px solid red;");
	}
	
	// Process for flag language
	$(".lang").click(function(){
		
		// Get name of current language
		var lang = $(this).attr("name");
		
		// Show hide language
		$("div[lang]").hide();
		$("div[lang="+lang+"]").show();
		
		// Flag
		$(".lang").attr("style", "border:0px solid red;");
		$("img[name="+lang+"]").attr("style", "border:1px solid red;");
		
	});
	
	//Process for change language
	$('.change-language').click(function(){
		var newCode = $(this).attr('id');
		newCode = '&code='+newCode;
		$.ajax({
			url:baseUrl+"/index/changelanguage",
			type:"POST",
			data:newCode,
			dataType:"json",
			complete:function(){
				window.location.href = landingPage;
			}
		});//END ajax
		
	});//END click
	
	
	//Process for delete news
	$(".delete-news").click(function(){
		var id = $(this).parents('div').children('.id_').html();
		id = '&id='+id;
		
		$( "#deleteconfirm" ).dialog({
			resizable: false,
			width:400,
			height:145,
			modal: true,
			buttons: {
				Delete: function(){
					lockScreen();
					$.ajax({
					  type: "POST",
					  url: baseUrl+'/news/deletenews',
					  dataType:"json",
					  data:id,
					  success:function(response){
						  console.log(response);
					  },
					}).done(function( msg ){
						window.location.href = "";
					});
					$(this).dialog( "close" );	
				},
				Cancel: function() {
					$(this).dialog( "close" );
				}
			}
		});	
	});
	
	$('.delete').click(function(){
		//Get url
		var id = $(this).parents('div').children('.id_').html();
		id = '&id='+id;
		$( "#deleteconfirm" ).dialog({
			resizable: false,
			width:400,
			height:145,
			modal: true,
			buttons: {
				Delete: function(){
					$.ajax({
					  type: "POST",
					  url: deletePath,
					  dataType:"json",
					  data:id,
					  success:function(response){
						  //console.log(response);
					  },
					}).done(function( msg ){
						window.location.href = "";
					});
					$(this).dialog( "close" );	
				},
				Cancel: function() {
					releaseScreen();
					$(this).dialog( "close" );
				}
			}
		});	
		
	});
	
	//Process for active news
	$(".activate-news").click(function(){
		var id = $(this).parents('div').children('.id_').html();
		id = '&id='+id;
		lockScreen();
		$.ajax({
		  type: "POST",
		  url: baseUrl+'/news/activatenews',
		  dataType:"json",
		  data:id,
		  success:function(response){
			  console.log(response);
		  },
		}).done(function( msg ){
			window.location.href = "";
		});//END ajax
		
	});
	
	//Process for active
	$(".activate").click(function(){
		var id = $(this).parents('div').children('.id_').html();
		id = '&id='+id;
		
		lockScreen();
		$.ajax({
		  type: "POST",
		  url: activePath,
		  dataType:"json",
		  data:id,
		  success:function(response){
			  console.log(response);
		  },
		}).done(function( msg ){
			window.location.href = "";
		});//END ajax
		
	});
	
	//Process for detail
	$(".detail").click(function(){
		var id = $(this).parents('div').children('.id_').html();
 		
		window.location.href = detailPath+'/id/'+id;
		
	});
	
	
	
	//Process Top Menu in Admin
	var current = $('.nav').find('.current');
	
	$('.nav .select').hover(function(){
		current.removeClass('current');	
	});

	$('.nav').mouseleave(function(){
		current.addClass('current');
	});
	
	
	
	
	
	
	
	// This is function of delete icon in list item
	$(".deleteList").click(function(){
		var id = $(this).parents('tr').find("input[name=id]").val();
		if(id != ""){
			$( ".deleteMessages" ).dialog({
				resizable: false,
				width:400,
				height:145,
				modal: true,
				buttons: {
					Delete: function(){
						$.ajax({
						  type: "POST",
						  url: baseUrl+"/group/del/id/"+id,
						  async: false,
						  dataType:"json"
						}).done(function( msg ){
							window.location.href = baseUrl+"/group/list/";
						});
						$(this).dialog( "close" );	
					},
					Cancel: function() {
						$(this).dialog( "close" );
					}
				}
			});	
		}
	});	
	
/*
	// process for flag language
	$(".lang").click(function(){
		
		// Get name of current language
		var lang = $(this).attr("name");
		
		// Show hide language
		$("tr[lang]").hide();
		$("tr[lang="+lang+"]").show();
		
		// Flag
		$(".lang").attr("style", "border:0px solid red;");
		$("img[name="+lang+"]").attr("style", "border:1px solid red;");
		
	});	
*/
	// Change page if the styledselect_pages select was be changed
	$('.styledselect_pages').change(function(val){
		alert("Hello");
	});
	
	// Delete multi row in list page
	$('.actionDelete').click(function(){
		var arrID = new Array();
		// Get all input was be selected and  put them into a array
		$('input[name=id]:checked').each(function(index){
			arrID[index] = $(this).val();	
		});
		if(arrID.length<=0){
			$( ".delRequireMessages" ).dialog({
				resizable: false,
				width:400,
				height:145,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog( "close" );
					}
				}
			});
		}else{
			$( ".deleteMessages" ).dialog({
				resizable: false,
				width:400,
				height:145,
				modal: true,
				buttons: {
					Delete: function(){
						// Give them over php to delete theme
						$.ajax({
							url:baseUrl+"/group/dels",
							type:"POST",
							async:false,
							data:{ids:arrID},
							dataType:"json",
							success:function(data){
								window.location.href = baseUrl+"/group/list/";
							}
						});
						$(this).dialog( "close" );	
					},
					Cancel: function() {
						$(this).dialog( "close" );
					}
				}
			});
		}
		return false;
	});
});